package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.entity.Group;
import org.dzms.entity.GroupDetail;

public class groupDetailDAO {
	/**
	 * ========================================================
	 * 												团购详情信息查询
	 * ========================================================
	 */
	//查询所有团购详情信息
	public List<GroupDetail> findAllGd() {
		String sql = "select *from groupdetail";
		return DataHandler.query(sql, null, GroupDetail.class);
	}
	//保存团购详情信息
	public void saveGd(GroupDetail gd) {
		String sql = "insert into groupdetail(gdshdetname, gdreview, "
					   	 + "gdaddress, gdtel, gdbushour, gdfoodname, gdfoodnum,"
						+ " gdunitprice, gdpic) values(?,?,?,?,?,?,?,?,?)";
		DataHandler.update(sql, new Object[]{gd.getGdshdetname(), gd.getGdreview(), 
																		gd.getGdaddress(), gd.getGdtel(), gd.getGdbushour(),
																		 gd.getGdfoodname(), gd.getGdfoodnum(), 
																		 gd.getGdunitprice(), gd.getGdpic()});
	}
	//删除团购详情信息
	public void deleteGd(int gdid) {
		String sql = "delete from groupdetail where gdid=?";
		DataHandler.update(sql, new Object[]{gdid});
	}
	//更新团购详情信息
	public void updateGd(GroupDetail gd) {
		String sql = "update groupdetail set gdshdetname=?, gdreview=?, "
						 + "gdaddress=?, gdtel=?, gdbushour=?, gdfoodname=?, "
						 + "gdfoodnum=?, gdunitprice=?, gdpic=? where gdid=?";
		DataHandler.update(sql, new Object[]{gd.getGdshdetname(), gd.getGdreview(), 
																		 gd.getGdaddress(), gd.getGdtel(), gd.getGdbushour(),
																		 gd.getGdfoodname(), gd.getGdfoodnum(), 
																		 gd.getGdunitprice(), gd.getGdpic(), gd.getGdid()});
	}
	
	public List<GroupDetail> findByGdId(int gdid) {
		String sql = "select *from groupdetail where gdid="+gdid;
		return DataHandler.query(sql, null, GroupDetail.class);
	}

}
